
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/11/1
 * Time: 9:38
 * Description:泛型类
 * <T>: 当前类 是一个 泛型类
 * 1、可以进行类型的检查
 * 2、可以进行类型的自动转换
 */
class MyArrayList <T> {
    public T[] elem;
    public int usedSize;

    public MyArrayList() {
        //this.elem = new T[10];
        this.elem = (T[])new Object[10];
    }

    public void add(T val) {
        this.elem[this.usedSize++] = val;
    }

    public T getPos(int pos) {
        return this.elem[pos];
    }

    public Object[] getArray(int size) {
        Object[] genericArray = new Object[size]; // suppose this is allowed
        return genericArray;
    }
}
class Person {

}
public class TestDemo2 {

    public static void main(String[] args) {
        MyArrayList<Integer> myArrayList1 = new MyArrayList<>();
        String[] ret = (String[])myArrayList1.getArray(2);
    }


    public static void main6(String[] args) {
        Integer i1 = 128;
        Integer i2 = 128;
        System.out.println(i1==i2);
    }

    public static void main5(String[] args) {
        int val = 10;
        Integer vv = 9;//自动的装箱
        Integer vv2 = new Integer(12);//显示装箱
        Integer vv3 = Integer.valueOf(13);//显示装箱
        int val2 = vv2;//自动的拆箱
        int val3 = vv2.intValue();
        double val33 = vv3.doubleValue();
        Integer iii = Integer.valueOf("123");
        System.out.println(iii);
    }


    public static void main4(String[] args) {

       /* Object[] array = new Object[10];
        Integer[] objects = (Integer[])array;
        */

       /* Integer[] integers = new Integer[5];
        Long[] longs = (Long[])integers;
        */

        /*Object object = null;
        Integer integer = (Integer) object;
*/
    }


    public static void main3(String[] args) {
        MyArrayList<Integer> myArrayList1 = new MyArrayList<>();
        MyArrayList<String> myArrayList2 = new MyArrayList<>();
        System.out.println(myArrayList1);
        System.out.println(myArrayList2);
    }

    public static void main2(String[] args) {
        MyArrayList<Integer> myArrayList1 = new MyArrayList<>();
        myArrayList1.add(1);
        myArrayList1.add(2);
        int val = myArrayList1.getPos(0);
        System.out.println(val);


        MyArrayList<String> myArrayList2 = new MyArrayList<>();
        myArrayList2.add("1");
        myArrayList2.add("1");
        myArrayList2.add("1");

        String str = myArrayList2.getPos(0);
        System.out.println(str);
    }

    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2.0);
        myArrayList.add("gaobo");
        double val = (double)myArrayList.getPos(0);
    }
}
